package com.ruoyi.project.manhua.comment.controller;

import java.util.List;

import com.ruoyi.project.manhua.climb.service.IMhClimbService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.manhua.comment.domain.MhComment;
import com.ruoyi.project.manhua.comment.service.IMhCommentService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 漫画评论
Controller
 *
 * @author yuan
 * @date 2021-01-27
 */
@Controller
@RequestMapping("/manhua/comment")
public class MhCommentController extends BaseController
{
    private String prefix = "manhua/comment";

    @Autowired
    private IMhCommentService mhCommentService;

    @Autowired
    private IMhClimbService mhClimbService;

    @RequiresPermissions("manhua:comment:view")
    @GetMapping("/{id}")
    public String comment(@PathVariable("id")Long id, ModelMap map)
    {
        map.put("nameId", id);
        map.put("MhNameDataAll",mhClimbService.mapMhNames());
        return prefix + "/comment";
    }

    /**
     * 查询漫画评论
列表
     */
    @RequiresPermissions("manhua:comment:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MhComment mhComment)
    {
        startPage();
        List<MhComment> list = mhCommentService.selectMhCommentList(mhComment);
        return getDataTable(list);
    }

    /**
     * 导出漫画评论
列表
     */
    @RequiresPermissions("manhua:comment:export")
    @Log(title = "漫画评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MhComment mhComment)
    {
        List<MhComment> list = mhCommentService.selectMhCommentList(mhComment);
        ExcelUtil<MhComment> util = new ExcelUtil<MhComment>(MhComment.class);
        return util.exportExcel(list, "comment");
    }

    /**
     * 新增漫画评论

     */
    @GetMapping("/add")
    public String add(ModelMap map)
    {
        map.put("MhNameDataAll",mhClimbService.mapMhNames());
        return prefix + "/add";
    }

    /**
     * 新增保存漫画评论

     */
    @RequiresPermissions("manhua:comment:add")
    @Log(title = "漫画评论", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MhComment mhComment)
    {
        return toAjax(mhCommentService.insertMhComment(mhComment));
    }

    /**
     * 修改漫画评论

     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MhComment mhComment = mhCommentService.selectMhCommentById(id);
        mmap.put("mhComment", mhComment);
        return prefix + "/edit";
    }

    /**
     * 修改保存漫画评论

     */
    @RequiresPermissions("manhua:comment:edit")
    @Log(title = "漫画评论", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MhComment mhComment)
    {
        return toAjax(mhCommentService.updateMhComment(mhComment));
    }

    /**
     * 删除漫画评论

     */
    @RequiresPermissions("manhua:comment:remove")
    @Log(title = "漫画评论", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mhCommentService.deleteMhCommentByIds(ids));
    }
}
